<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <title> 小程序管理系统</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="format-detection" content="telephone=no">

  <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css"  media="all">
  <style type="text/css">
    .layui-table{
      text-align: center;
    }
    .layui-table td, .layui-table th{
      text-align: center;
    }
    .yueshu{
      /*display:-webkit-box !important;*/
      overflow: hidden;
      text-overflow: ellipsis;
      word-break: break-all;


    }
  </style>
</head>
<body>
<div class="layui-layout layui-layout-admin">

  <input type="hidden" id = "type" value = "{$res['type']}"/>
  <!--菜单列表-->
  <div id = "divhead"></div>
  <div class="layui-body">
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
      <legend>社区管理</legend>
    </fieldset>
    <!-- 内容主体区域 -->
      <div id="view"></div>
  </div>

  <div class="layui-footer">
    <!-- 底部固定区域 -->
    <!--© 2017-2018 <a href="https://www.58zltc.com" target="_blank">  </a> All Rights Reserved.-->
  </div>
</div>



<script id="common_tpl" type="text/html">

  <table class="layui-table">
    <thead>
    <tr>
      <th>ID</th>
      <th>用户昵称</th>
      <th>标题</th>
      <th>内容</th>
      <if condition="$res['type'] == 1"><th>相关书籍</th></if>

      <if condition="$res['type'] == 4"><th>文章类型</th></if>

      <if condition="$res['type'] != 3"><th>点赞数目</th></if>

      <th>浏览数目</th>
      <th>添加时间</th>
      <th>操作</th>
    </tr>
    </thead>
    <tbody>
    {{#  layui.each(d, function(index, item){ }}
    <tr>
      <td>{{ item.id }}</td>
      <td>{{ item.nickname }}</td>
      <td>{{ item.title }}</td>
      <td class = "yueshu">{{ item.content }}</td>

      <if condition="$res['type'] == 1"><td>{{ item.xiangguanbook }}</td></if>
      <if condition="$res['type'] == 4"><td>{{ item.wenzhangtype }}</td></if>

      <if condition="$res['type'] != 3"><td>{{ item.dianzan_num }}</td></if>

      <td>{{ item.liulan_num }}</td>
      <td>{{ item.time }}</td>
      <td style = "width:250px;">
        <button data-id="{{ item.id }}" class="edit layui-btn layui-btn-small">编辑</button>
        <button data-id="{{ item.id }}" class="del layui-btn layui-btn-small">删除</button>
      </td>
    </tr>
    {{#  }); }}
    </tbody>
  </table>
  <div id="page-box"></div>
</script>



<script src="__PUBLIC__/layui/layui.js" charset="utf-8"></script>
<script src="__PUBLIC__/js/jquery-1.11.1.min.js" charset="utf-8"></script>
<script>
    $(function(){
        $('#divhead').load('/index.php/Tongcheng/Index/menu/wid/2.html');
    })
    //JavaScript代码区域
    layui.use(['element','laypage','laytpl','layer'], function(){
        var element = layui.element
            ,$ = layui.jquery
            ,layer = layui.layer
            ,laytpl = layui.laytpl
            ,laypage = layui.laypage;
        var count = $("#count").val();
        var type = $("#type").val();

        $("#view").on('click', '.edit', function(event) {
            var id = $(this).data('id');
            layer.open({
                type: 2,
                title: '查看',
                shadeClose: true,
                shade: false,
                maxmin: true, //开启最大化最小化按钮
                area: ['400px', '600px'],
                content: '{:U("edit")}?id='+ id
            });
        });
        $("#view").on('click', '.del', function(event) {
            var id = $(this).data('id');
            layer.confirm('你确定要删除该数据？', {
                btn: ['确定','取消'] //按钮
            }, function(){
            $.get('{:U("del")}?id='+ id,function(e){
                if(1 == e){
                    layer.alert('删除成功');
                    setTimeout(function(){
                        location.reload();
                    },1000);
                }else{
                    layer.alert('删除失败');
                }
            })
            },function(){
            });
        });

        getList(1, 10,type);

        function getList(page, limit,type){
            console.log('type==='+type)
            $.get("{:U('index')}?page="+page+"&limit="+limit+"&type="+type,function(data){
                var view = document.getElementById('view');
                var getTpl = common_tpl.innerHTML;
                laytpl(getTpl).render(data.list, function(html){
                    view.innerHTML = html;
                });
                laypage.render({
                    elem: 'page-box'
                    ,count: data.count
                    ,limit:limit
                    ,curr: page
                    ,layout: ['count', 'prev', 'page', 'next', 'limit', 'skip']
                    ,jump: function(obj, first){
                        console.log(obj)
                        if(!first){
                            getList(obj.curr, obj.limit,type);
                        }
                    }
                });
            })
        }
    });
</script>
</body>
</html>
